package org.linlinjava.litemall.db.service;

import java.time.LocalDateTime;
import java.util.List;

import javax.annotation.Resource;

import org.linlinjava.litemall.db.dao.LitemallOrderTaxMapper;
import org.linlinjava.litemall.db.dao.OrderTaxMapper;
import org.linlinjava.litemall.db.domain.LitemallOrderTax;
import org.linlinjava.litemall.db.domain.LitemallOrderTaxExample;
import org.linlinjava.litemall.db.domain.TaxStatisticsDetailVo;
import org.springframework.stereotype.Service;

/**
 * @author ：stephen
 * @date ：Created in 2020/5/13 16:31
 * @description：TODO
 */
@Service
public class LitemallOrderTaxService {
    @Resource
    private LitemallOrderTaxMapper litemallOrderTaxMapper;
    @Resource
    private OrderTaxMapper orderTaxMapper;


    public LitemallOrderTax findById(Integer id) {
        return litemallOrderTaxMapper.selectByPrimaryKey(id);
    }


    public int add(LitemallOrderTax record){
        record.setAddTime(LocalDateTime.now());
        return litemallOrderTaxMapper.insertSelective(record);
    }

    public int update(LitemallOrderTax record){
        return litemallOrderTaxMapper.updateByPrimaryKeySelective(record);
    }
    public List<LitemallOrderTax> queryByOrderId(Integer orderId){
        LitemallOrderTaxExample example = new LitemallOrderTaxExample();
        example.or().andOrderIdEqualTo(orderId).andDeletedEqualTo(false);
        return litemallOrderTaxMapper.selectByExample(example);
    }

    public int deleteById(Integer id) {
        return litemallOrderTaxMapper.deleteByPrimaryKey(id);
    }
    
    public int deleteByOrderId(Integer orderId) {
    	LitemallOrderTaxExample example = new LitemallOrderTaxExample();
        example.or().andOrderIdEqualTo(orderId).andDeletedEqualTo(false);
    	return litemallOrderTaxMapper.deleteByExample(example);
    }

    public int logicDeleteByOrderId(Integer orderId) {
        LitemallOrderTaxExample example = new LitemallOrderTaxExample();
        example.or().andOrderIdEqualTo(orderId).andDeletedEqualTo(false);
        return litemallOrderTaxMapper.logicalDeleteByExample(example);
    }
    
    public int deleteByOrderIdAndOrderGoodsId(Integer orderId, Integer orderGoodsId) {
    	LitemallOrderTaxExample example = new LitemallOrderTaxExample();
    	example.or().andOrderIdEqualTo(orderId).andOrderGoodsIdEqualTo(orderGoodsId).andDeletedEqualTo(false);
    	return litemallOrderTaxMapper.deleteByExample(example);
    }
    
    public List<LitemallOrderTax> queryByOrderIdAndOrderGoodsId(Integer orderId, Integer orderGoodsId){
    	LitemallOrderTaxExample example = new LitemallOrderTaxExample();
    	example.or().andOrderIdEqualTo(orderId).andOrderGoodsIdEqualTo(orderGoodsId).andDeletedEqualTo(false);
        return litemallOrderTaxMapper.selectByExample(example);
    }

    public LitemallOrderTax queryByOrderIdAndOrderGoodsIdAndCode(Integer orderId, Integer orderGoodsId,String code){
        LitemallOrderTaxExample example = new LitemallOrderTaxExample();
        example.or().andOrderIdEqualTo(orderId).andOrderGoodsIdEqualTo(orderGoodsId).andCodeEqualTo(code).andDeletedEqualTo(false);
        return litemallOrderTaxMapper.selectOneByExample(example);
    }
    
    public List<TaxStatisticsDetailVo> monthStatistics(String startTime,String endTime, Integer shopId) {
    	return orderTaxMapper.monthStatistics(startTime, endTime, shopId);
    }
    
    public List<TaxStatisticsDetailVo> dayStatistics(Integer shopId, String searchDate) {
    	return orderTaxMapper.dayStatistics(searchDate, shopId);
    }
    
    public List<TaxStatisticsDetailVo> hourStatistics(Integer shopId, String time, String searchHour) {
    	return orderTaxMapper.hourStatistics( time,searchHour.trim(), shopId);
    }
    
    public List<TaxStatisticsDetailVo> dayStatisticsByOrderId(Integer orderId) {
    	return orderTaxMapper.dayStatisticsByOrderId(orderId);
    }
    
    public List<TaxStatisticsDetailVo> totalStatistics(String startTime,String endTime, Integer shopId, Integer regionId,Integer status) {
    	return orderTaxMapper.totalStatistics(startTime, endTime, regionId, shopId,status);
    }
}
